namespace EYangFrame.DataAccess.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitAuth : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "SCOTT.EYANG_MENU",
                c => new
                    {
                        ID = c.Guid(nullable: false),
                        FORMTYPE = c.String(maxLength: 200),
                        MENUNAME = c.String(maxLength: 100),
                        CREATETIME = c.DateTime(nullable: false),
                        CREATEUSER = c.String(),
                    })
                .PrimaryKey(t => t.ID);
            
            CreateTable(
                "SCOTT.EYANG_ROLE",
                c => new
                    {
                        ID = c.Guid(nullable: false),
                        ROLENAME = c.String(maxLength: 20),
                        CREATETIME = c.DateTime(nullable: false),
                        CREATEUSER = c.String(),
                        PARENT_ID = c.Guid(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("SCOTT.EYANG_ROLE", t => t.PARENT_ID)
                .Index(t => t.PARENT_ID);
            
            CreateTable(
                "SCOTT.EYANG_NAVIGATION",
                c => new
                    {
                        ID = c.Guid(nullable: false),
                        NAVIGATIONNAME = c.String(maxLength: 20),
                        NAVIGATIONTYPE = c.Decimal(nullable: false, precision: 10, scale: 0),
                        ORDER = c.Decimal(nullable: false, precision: 10, scale: 0),
                        URL = c.String(maxLength: 200),
                        BGIMAGE = c.String(maxLength: 100),
                        CREATETIME = c.DateTime(nullable: false),
                        CREATEUSER = c.String(),
                        PREVIEWNAVIGATION_ID = c.Guid(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("SCOTT.EYANG_NAVIGATION", t => t.PREVIEWNAVIGATION_ID)
                .Index(t => t.PREVIEWNAVIGATION_ID);
            
            CreateTable(
                "SCOTT.EYANG_USER",
                c => new
                    {
                        ID = c.Guid(nullable: false),
                        USERNAME = c.String(maxLength: 50),
                        GENDER = c.Decimal(nullable: false, precision: 10, scale: 0),
                        EMAIL = c.String(maxLength: 50),
                        PHONE = c.String(maxLength: 20),
                        ISADMIN = c.Decimal(nullable: false, precision: 1, scale: 0),
                        ISLOCKED = c.Decimal(nullable: false, precision: 1, scale: 0),
                        ISDELETE = c.Decimal(nullable: false, precision: 1, scale: 0),
                        PASSWORD = c.String(maxLength: 50),
                        CHANGEPASSWORD = c.Decimal(nullable: false, precision: 1, scale: 0),
                        CREATETIME = c.DateTime(nullable: false),
                        CREATEUSER = c.String(),
                        LEADER_ID = c.Guid(),
                        ROLE_ID = c.Guid(),
                    })
                .PrimaryKey(t => t.ID)
                .ForeignKey("SCOTT.EYANG_USER", t => t.LEADER_ID)
                .ForeignKey("SCOTT.EYANG_ROLE", t => t.ROLE_ID)
                .Index(t => t.LEADER_ID)
                .Index(t => t.ROLE_ID);
            
            CreateTable(
                "SCOTT.RoleMenus",
                c => new
                    {
                        Role_ID = c.Guid(nullable: false),
                        Menu_ID = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Role_ID, t.Menu_ID })
                .ForeignKey("SCOTT.EYANG_ROLE", t => t.Role_ID, cascadeDelete: true)
                .ForeignKey("SCOTT.EYANG_MENU", t => t.Menu_ID, cascadeDelete: true)
                .Index(t => t.Role_ID)
                .Index(t => t.Menu_ID);
            
            CreateTable(
                "SCOTT.NavigationRoles",
                c => new
                    {
                        Navigation_ID = c.Guid(nullable: false),
                        Role_ID = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Navigation_ID, t.Role_ID })
                .ForeignKey("SCOTT.EYANG_NAVIGATION", t => t.Navigation_ID, cascadeDelete: true)
                .ForeignKey("SCOTT.EYANG_ROLE", t => t.Role_ID, cascadeDelete: true)
                .Index(t => t.Navigation_ID)
                .Index(t => t.Role_ID);
            
            CreateTable(
                "SCOTT.UserMenus",
                c => new
                    {
                        User_ID = c.Guid(nullable: false),
                        Menu_ID = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.User_ID, t.Menu_ID })
                .ForeignKey("SCOTT.EYANG_USER", t => t.User_ID, cascadeDelete: true)
                .ForeignKey("SCOTT.EYANG_MENU", t => t.Menu_ID, cascadeDelete: true)
                .Index(t => t.User_ID)
                .Index(t => t.Menu_ID);
            
            CreateTable(
                "SCOTT.UserNavigations",
                c => new
                    {
                        User_ID = c.Guid(nullable: false),
                        Navigation_ID = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.User_ID, t.Navigation_ID })
                .ForeignKey("SCOTT.EYANG_USER", t => t.User_ID, cascadeDelete: true)
                .ForeignKey("SCOTT.EYANG_NAVIGATION", t => t.Navigation_ID, cascadeDelete: true)
                .Index(t => t.User_ID)
                .Index(t => t.Navigation_ID);
            
        }
        
        public override void Down()
        {
            DropForeignKey("SCOTT.EYANG_ROLE", "PARENT_ID", "SCOTT.EYANG_ROLE");
            DropForeignKey("SCOTT.EYANG_USER", "ROLE_ID", "SCOTT.EYANG_ROLE");
            DropForeignKey("SCOTT.UserNavigations", "Navigation_ID", "SCOTT.EYANG_NAVIGATION");
            DropForeignKey("SCOTT.UserNavigations", "User_ID", "SCOTT.EYANG_USER");
            DropForeignKey("SCOTT.UserMenus", "Menu_ID", "SCOTT.EYANG_MENU");
            DropForeignKey("SCOTT.UserMenus", "User_ID", "SCOTT.EYANG_USER");
            DropForeignKey("SCOTT.EYANG_USER", "LEADER_ID", "SCOTT.EYANG_USER");
            DropForeignKey("SCOTT.NavigationRoles", "Role_ID", "SCOTT.EYANG_ROLE");
            DropForeignKey("SCOTT.NavigationRoles", "Navigation_ID", "SCOTT.EYANG_NAVIGATION");
            DropForeignKey("SCOTT.EYANG_NAVIGATION", "PREVIEWNAVIGATION_ID", "SCOTT.EYANG_NAVIGATION");
            DropForeignKey("SCOTT.RoleMenus", "Menu_ID", "SCOTT.EYANG_MENU");
            DropForeignKey("SCOTT.RoleMenus", "Role_ID", "SCOTT.EYANG_ROLE");
            DropIndex("SCOTT.EYANG_ROLE", new[] { "PARENT_ID" });
            DropIndex("SCOTT.EYANG_USER", new[] { "ROLE_ID" });
            DropIndex("SCOTT.UserNavigations", new[] { "Navigation_ID" });
            DropIndex("SCOTT.UserNavigations", new[] { "User_ID" });
            DropIndex("SCOTT.UserMenus", new[] { "Menu_ID" });
            DropIndex("SCOTT.UserMenus", new[] { "User_ID" });
            DropIndex("SCOTT.EYANG_USER", new[] { "LEADER_ID" });
            DropIndex("SCOTT.NavigationRoles", new[] { "Role_ID" });
            DropIndex("SCOTT.NavigationRoles", new[] { "Navigation_ID" });
            DropIndex("SCOTT.EYANG_NAVIGATION", new[] { "PREVIEWNAVIGATION_ID" });
            DropIndex("SCOTT.RoleMenus", new[] { "Menu_ID" });
            DropIndex("SCOTT.RoleMenus", new[] { "Role_ID" });
            DropTable("SCOTT.UserNavigations");
            DropTable("SCOTT.UserMenus");
            DropTable("SCOTT.NavigationRoles");
            DropTable("SCOTT.RoleMenus");
            DropTable("SCOTT.EYANG_USER");
            DropTable("SCOTT.EYANG_NAVIGATION");
            DropTable("SCOTT.EYANG_ROLE");
            DropTable("SCOTT.EYANG_MENU");
        }
    }
}
